package com.itheima.sh;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author 张伟奇
 * @Date 2021/5/17 17:00
 * @Version 1.0
 **/
@WebServlet("/getRealPathServlet")
public class GetRealPathServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

//        String filename = req.getParameter("filename");
//        ServletContext servletContext = getServletContext();
//        String mimeType = servletContext.getMimeType(filename);
//        System.out.println(mimeType);
//        resp.getWriter().print(mimeType);

        String filename = req.getParameter("filename");
        ServletContext servletContext = getServletContext();

        String realPath = servletContext.getRealPath("");
        String realPath1 = servletContext.getRealPath("/");
        String realPath2 = servletContext.getRealPath("/download/"+filename);
        System.out.println(realPath);
        System.out.println(realPath1);
        System.out.println(realPath2);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
}
